package com.quick.api.config;

import java.util.List;

/**
 * @author ：chicunxiang
 * @date ：Created in 2021/3/25 13:52
 * @description：
 * @version: 1.0
 */
public class DynamicDataSourceContextHolder {

    // 定义一个ThreadLocal变量，保存数据源类型（保证线程安全，多个线程之间互不影响）
    private static final ThreadLocal<String> DATA_SOURCE_CONTEXT_HOLDER = new ThreadLocal<>();

    public static String DEFAULT_DATA_SOURCE = "";

    public static boolean DATA_SOURCE_IS_ONE = false;

    public static List<String> DATA_SOURCE_KEYS;

    public static void setDefaultDataSource() {
        DATA_SOURCE_CONTEXT_HOLDER.set(DEFAULT_DATA_SOURCE);
    }

    public static void setDataSource(String key) {
        DATA_SOURCE_CONTEXT_HOLDER.set(key);
    }

    public static String getDataSource() {
        return DATA_SOURCE_CONTEXT_HOLDER.get();
    }
}